package item;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import platform.Platform;
import player.Player;

public class DefaultEquipment extends BaseItem implements Equipment, java.io.Serializable{

	protected int duration;

	public DefaultEquipment(ItemTemplate template, long id, int instanceId,long createTimeStamp){
		super(template,id,instanceId,createTimeStamp);
	}
	
	public DefaultEquipment(ItemTemplate template, long id, int instanceId){
		super(template,id,instanceId);
	}
	
	public EquipmentTemplate getTemplate(){
		return (EquipmentTemplate)super.getTemplate();
	}
	
	public void enhance(PropertyCalculator pc)
	{
		
	}
		
	@Override
	public int getDuration() {
		return duration;
	}

	@Override
	public int getMagicPower() {
		return 0;
	}

	@Override
	public int getMaxAttack() {
		return 0;
	}

	@Override
	public int getMinAttack() {
		return 0;
	}

	private void writeObject(ObjectOutputStream stream) throws IOException{
		stream.defaultWriteObject();
		stream.writeInt(this.getTemplate().getId());
	}
	
	private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException{
		stream.defaultReadObject();
		int equTemplateId = stream.readInt();
		ItemTemplate template = Platform.getAppContext().get(ItemService.class).getItemTemplate(equTemplateId);
		this.template = template;
	}

	@Override
	public void setDuration(int duration, Player owner) {
		/*if(this.duration != duration){
			this.duration = duration;
			if(owner != null){
				owner.getChanged().addChangedItem(new DurationChangedItem(this));
			}
		}*/	
	}
}
